/*
 * ------------------------------------------------------------------
 * 菜单操作 模块
 * ------------------------------------------------------------------
 * @关于我：
 * QQ:2815473064
 * wechat:13531609457
 * ------------------------------------------------------------------
 */

import config from "@/config";
const {
    // 路由菜单缓存状态
    RouterMenusStorage,
    // 路由菜单缓存方式  localstorage 或者 sessionStorage
    RouterMenusStorageType,
    // 路由菜单缓存访问Key
    RouterMenusStorageKey,
} = config
// localstorage 操作模块
import localStorageModule from "../localStorage";
// SessionStorage 操作模块
import SessionStorageModule from "../sessionStorage"
// 获取菜单列表
export const GetMenusList = function () {
    let menusList = []
    if (RouterMenusStorage) {
        if (RouterMenusStorageType == "localstorage") {
            menusList = localStorageModule.get(RouterMenusStorageKey)
        } else if (RouterMenusStorageType == "sessionStorage") {
            menusList = SessionStorageModule.get(RouterMenusStorageKey)
        }
    }
    return menusList || []
}
// 设置菜单列表
export const SetMenusList = function (data) {
    if (RouterMenusStorage) {
        if (RouterMenusStorageType == "localstorage") {
            localStorageModule.save({
                key: RouterMenusStorageKey,
                value: data,
                encrypt: false,
            })
            return true
        } else if (RouterMenusStorageType == "sessionStorage") {
            SessionStorageModule.save({
                key: RouterMenusStorageKey,
                value: data,
                encrypt: false,
            })

            return true
        } else {
            return false
        }
    } else {
        return false
    }
}
// 清空菜单列表
export const EmptyMenusList = function () {
    // 是否开启Token 本地存储
    if (!RouterMenusStorage) { return false }
    if (RouterMenusStorageType == "localStorage") {
        localStorageModule.remove(RouterMenusStorageKey)
    } else if (RouterMenusStorageType == "sessionStorage") {
        SessionStorageModule.remove(RouterMenusStorageKey)
    }
}
export default {
    EmptyMenusList,
    SetMenusList,
    GetMenusList
}

